package th.co.exat.uap.util.date;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class FormateDate {

    public static String now() {
        Locale locale = new Locale("th", "TH");
        SimpleDateFormat simple_date_format =
                new SimpleDateFormat("dd/MM/yyyy", locale);
        String dt = simple_date_format.format(new Date());

        return dt;
    }

    public static String convertDateTimeToDatabase(String date,String hour,String minute) throws ParseException {
        Locale locale = new Locale("th", "TH");
        DateFormat dateSource = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss",locale);
        Date d = dateSource.parse(date + " " + hour + ":" + minute + ":00");

        DateFormat dateDestination = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",locale);

        return dateDestination.format(d);
    }

    public static String convertDateToDatabase(String date) throws ParseException {
        Locale locale = new Locale("th", "TH");
        DateFormat dateSource = new SimpleDateFormat("dd/MM/yyyy",locale);
        Date d = dateSource.parse(date);

        DateFormat dateDestination = new SimpleDateFormat("yyyy-MM-dd",locale);

        return dateDestination.format(d);
    }

    public static String convertDateTimeToWebapp(String date) throws ParseException {
        Locale locale = new Locale("th", "TH");
        DateFormat dateSource = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",locale);
        Date d = dateSource.parse(date);

        DateFormat dateDestination = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss",locale);

        return dateDestination.format(d);
    }
}
